import * as vscode from "vscode";
import { FileNameNotesProvider } from "./FileNameNotes";
import { ColorsViewProvider } from "./ColorsViewProvider";
import { varsUsedProvider } from "./VarsUsedTreeViewProvider";
import { ColorQuickPicker } from "./ColorQuickPicker";
import { ColorDecorationProvider } from "./ColorDecoration";
import { EngineProvider } from "./EngineProvider";
import { MirtxtLanguageFormatter } from "./MirtxtLanguageFormatter";

let engineProvider: EngineProvider | undefined = undefined;
const plugin = vscode.extensions.getExtension("mir-script-plugin");
plugin?.activate().then((engine?: EngineProvider) => {
  engineProvider = engine;
});

const providers = {
  engine: new EngineProvider(),
  fileNoteDecoration: new FileNameNotesProvider(),
  colorsView: new ColorsViewProvider(),
  varsUsed: new varsUsedProvider(),
  // 自动填充颜色
  colorsCompletion: new ColorQuickPicker(),
  colorDecoration: new ColorDecorationProvider(),
  formatter: new MirtxtLanguageFormatter(),
};
export interface MirServerProvider {
  activate: () => void;
}
type MirServer = { context: vscode.ExtensionContext; providers: typeof providers };
export let mirServer: MirServer;
export function activate(context: vscode.ExtensionContext) {
  // vscode.window.showInformationMessage("欢迎使用Mir-Script-Language");
  mirServer = { providers, context };
  if (engineProvider) {
    providers.engine.deactivate();
  } else {
    engineProvider = providers.engine;
  }
  mirServer.providers.engine = engineProvider;
  for (const provider of Object.values(providers)) {
    provider.activate();
  }
  return engineProvider;
}

export { engineProvider };

export function deactivate() {}
